﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class LanManager : NetworkDiscovery {
    public delegate void OnReceiveBordadcastDelegate(string fromAddress_, string roomName_, 
        int port_, int gameMode_, string slotCount_);
    public OnReceiveBordadcastDelegate OnReceiveClbk;
    public override void OnReceivedBroadcast(string fromAddress, string data) {
        base.OnReceivedBroadcast(fromAddress, data);
        // Debug.Log($"Find: {fromAddress}, data: {data}");

        var address = fromAddress.Split(':')[3];
        var broadcastInfo = data.Split(',');
        var roomName = broadcastInfo[0];
        var port = int.Parse(broadcastInfo[1]);
        var gameMode = int.Parse(broadcastInfo[2]);
        var slotCount = broadcastInfo[3];
        if (null != OnReceiveClbk) { 
            OnReceiveClbk(address, roomName, port, gameMode, slotCount);
        }
    }
}
